package com.store.app.imlife.utils;

import android.app.Activity;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;

/**
 * 网络处理工具
 * @zhouyiliang Administrator
 *
 */
public class NetTools {
	/** 
	 * 是否连接网络
	 *  
	 * @param context 
	 * @return 
	 */  
	public static boolean isConnectedNetwrok(Context context)  
	{  

		ConnectivityManager connectivity = (ConnectivityManager) context  
				.getSystemService(Context.CONNECTIVITY_SERVICE);  

		if (null != connectivity)  
		{  
			NetworkInfo info = connectivity.getActiveNetworkInfo();
			if (null != info && info.isConnected())
			{  
				if (info.getState() == NetworkInfo.State.CONNECTED)  
				{  
					return true;  
				}  
			}  
		}  
		return false;  
	}  

	/** 
	 * 是否连接wifi
	 */  
	public static boolean isConnectedWifi(Context context)  
	{  
		ConnectivityManager cm = (ConnectivityManager) context  
				.getSystemService(Context.CONNECTIVITY_SERVICE);
		if (cm == null){
		}else{
		}
		NetworkInfo networkinfo = cm.getActiveNetworkInfo();
		if (null == networkinfo || !networkinfo.isAvailable()) {
			return false;
		}
		return true;
	}

	/** 
	 * 打开网络设置页面
	 */  
	public static void openSettingNetwork(Activity activity)  
	{  
		Intent intent = new Intent("/");  
		ComponentName cm = new ComponentName("com.android.settings",  
				"com.android.settings.WirelessSettings");  
		intent.setComponent(cm);  
		intent.setAction("android.intent.action.VIEW");  
		activity.startActivityForResult(intent, 0);  
	}  
}
